package com.hua.designpattern.behavioral.strategy;

/**
 * 
 * @author joshua
 *
 *         <pre>
 *
 *  策略模式（Strategy Pattern）中，一个类的行为或其算法可以在运行时更改。
 *      
 *	优点： 1、算法可以自由切换。 2、避免使用多重条件判断。 3、扩展性良好。
 *	缺点： 1、策略类会增多。
 *
 *
 *         </pre>
 *
 */
public class TestStrategy {

	public static void main(String[] args) {
		StrategyInterface addStrategy = new StrategyPlus();
		StrategyInterface subtractStrategy = new StrategySubtract();
		StrategyInterface multiplyStrategy = new StrategyMultiply();

		Calculator calculator1 = new Calculator(addStrategy);
		System.out.println("7+2= " + calculator1.getResult(7, 2));
		Calculator calculator2 = new Calculator(subtractStrategy);
		System.out.println("7-2= " + calculator2.getResult(7, 2));
		Calculator calculator3 = new Calculator(multiplyStrategy);
		System.out.println("7*2= " + calculator3.getResult(7, 2));

	}

}
